include(['PClass'], 

function(){
	
	declare('shapes.Point');
	Point = PClass.create({
		x : 0,
		y : 0,
		last : null,
		color : "orange",
		init: function(x,y){
			this.reset(x,y);
		},
		reset: function(x,y){
			this.x = x;
			this.y = y;
		},
		move : function(x,y){
			if( this.last ){
				this.x = this.last.x;
				this.y = this.last.y;
			}else{
				this.last = {}
				this.last.x = this.x;
				this.last.y = this.y;
			}
			this.reset(this.x+x,this.y+y);
		},
		render : function(gw){
			var c = gw.c;
			c.beginPath();
			//c.strokeStyle = this.color;
			c.fillStyle = this.color;
			c.lineWidth = 1;
			c.arc(this.x, this.y, 3, 0, Math.PI*2, true);
			c.fill();
			//console.log(this.color);
		},	
		setActive : function(value){
			
		},
		intersects : function( point, tolerance ){
			tolerance = tolerance || 3
			var intersects = (this.x - tolerance <= point.x && point.x <= this.x +tolerance) && 
				   (this.y - tolerance <= point.y && point.y <= this.y +tolerance);
			//console.log("Point intersection: " + intersects +" x (" + this.x + " == " + point.x +") "+ " y (" + this.y + " == " + point.y +") ~" + tolerance);
			if( intersects ) return [this];
			return null;
		}
	}, 'Point');
	Point.intersection = function(p1, p2, tolerance){
		tolerance = tolerance || 3
		var intersects = 
			(p1.x - tolerance <= p2.x && p2.x <= p1.x +tolerance) && 
		    (p1.y - tolerance <= p2.y && p2.y <= p1.y +tolerance);
		//console.log("Point intersection: " + intersects +" x (" + this.x + " == " + point.x +") "+ " y (" + this.y + " == " + point.y +") ~" + tolerance);
		if( intersects ) return [p1];
		return null;
	};
});